package com.lily.aidouzixun.bean;

import android.os.Parcel;
import android.os.Parcelable;

import com.alibaba.fastjson.JSONObject;

/**
 * 动态信息
 */
public class DynamicInfo implements Parcelable {

    /**
     * Json key
     */
    private static final String DID_JSONKEY= "DID";
    private static final String URID_JSONKEY= "URID";
    private static final String CONTENT_JSONKEY= "Content";
    private static final String IMAGE_JSONKEY= "Image";
    private static final String PUBTIME_JSONKEY= "PubTime";
    private static final String STATE_JSONKEY= "State";
    private static final String TYPE_JSONKEY= "Type";
    private static final String AVATAR_JSONKEY = "Avatar";
    private static final String NICKNAME_JSONKEY = "NickName";
    private static final String SUPPORT_JSONKEY = "Support";
    private static final String NEUTRAL_JSONKEY = "Neutral";
    private static final String OPPOSITION_JSONKEY = "Opposition";
    private static final String COMMENTS_JSONKEY = "Comments";
    private static final String IS_SUPPORT_JSONKEY = "isSupport";
    private static final String IS_COLLECT_JSONKEY = "isCollect";
    /**
     * 属性值
     */
    private String avatar; //用户头像
    private String nickName;
    private String did;
    private String urid;
    private String content;
    private String imageUrl;
    private String pubtime;
    private int state;  //状态 1-可用;2-不可用
    private int type;	//状态 1-真实用户;2-匿名用户
    private int support;
    private int neutral;
    private int opposition;
    private int comments;
    private int isSupport;  //是否点过赞，0-没有；1-点过
    private int isCollect;  //是否收藏过，0-没有；1-收藏过

    public int getIsCollect() {
        return isCollect;
    }

    public void setIsCollect(int isCollect) {
        this.isCollect = isCollect;
    }

    public int getIsSupport() {
        return isSupport;
    }

    public void setIsSupport(int isSupport) {
        this.isSupport = isSupport;
    }

    public int getComments() {
        return comments;
    }

    public void setComments(int comments) {
        this.comments = comments;
    }

    public int getNeutral() {
        return neutral;
    }

    public void setNeutral(int neutral) {
        this.neutral = neutral;
    }

    public int getOpposition() {
        return opposition;
    }

    public void setOpposition(int opposition) {
        this.opposition = opposition;
    }

    public int getSupport() {
        return support;
    }

    public void setSupport(int support) {
        this.support = support;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    /**
     * 用户头像
     * @return
     */
    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getUrid() {
        return urid;
    }

    public void setUrid(String urid) {
        this.urid = urid;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public String getPubtime() {
        return pubtime;
    }

    public void setPubtime(String pubtime) {
        this.pubtime = pubtime;
    }

    public String getDid() {
        return did;
    }

    public void setDid(String did) {
        this.did = did;
    }

    public String getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }

    /**
     * 解析文章列表数据
     * @param jsonObj
     * @return
     */
    public static DynamicInfo parseInfo(JSONObject jsonObj) {
        if (jsonObj == null) {
            return null;
        }
        DynamicInfo discussInfo = new DynamicInfo();
        if (jsonObj.has(AVATAR_JSONKEY)) {
            discussInfo.setAvatar(jsonObj.optString(AVATAR_JSONKEY));
        }
        if (jsonObj.has(NICKNAME_JSONKEY)) {
            discussInfo.setNickName(jsonObj.optString(NICKNAME_JSONKEY));
        }
        if (jsonObj.has(DID_JSONKEY)) {
            discussInfo.setDid(jsonObj.optString(DID_JSONKEY));
        }
        if (jsonObj.has(URID_JSONKEY)) {
            discussInfo.setUrid(jsonObj.optString(URID_JSONKEY));
        }
        if (jsonObj.has(CONTENT_JSONKEY)) {
            discussInfo.setContent(jsonObj.optString(CONTENT_JSONKEY));
        }
        if (jsonObj.has(IMAGE_JSONKEY)) {
            discussInfo.setImageUrl(jsonObj.optString(IMAGE_JSONKEY));
        }
        if (jsonObj.has(PUBTIME_JSONKEY)) {
            discussInfo.setPubtime(jsonObj.optString(PUBTIME_JSONKEY));
        }
        if (jsonObj.has(STATE_JSONKEY)) {
            discussInfo.setState(Integer.parseInt(jsonObj.optString(STATE_JSONKEY)));
        }
        if (jsonObj.has(TYPE_JSONKEY)) {
            discussInfo.setType(Integer.parseInt(jsonObj.optString(TYPE_JSONKEY)));
        }
        if (jsonObj.has(SUPPORT_JSONKEY)) {
            discussInfo.setSupport(Integer.parseInt(jsonObj.optString(SUPPORT_JSONKEY)));
        }
        if (jsonObj.has(NEUTRAL_JSONKEY)) {
            discussInfo.setNeutral(Integer.parseInt(jsonObj.optString(NEUTRAL_JSONKEY)));
        }
        if (jsonObj.has(OPPOSITION_JSONKEY)) {
            discussInfo.setOpposition(Integer.parseInt(jsonObj.optString(OPPOSITION_JSONKEY)));
        }
        if (jsonObj.has(COMMENTS_JSONKEY)) {
            discussInfo.setComments(Integer.parseInt(jsonObj.optString(COMMENTS_JSONKEY)));
        }
        if (jsonObj.has(IS_SUPPORT_JSONKEY)) {
            discussInfo.setIsSupport(jsonObj.optInt(IS_SUPPORT_JSONKEY));
        }
        if (jsonObj.has(IS_COLLECT_JSONKEY)) {
            discussInfo.setIsCollect(jsonObj.optInt(IS_COLLECT_JSONKEY));
        }
        return discussInfo;
    }

    /**
     * 序列化实体类
     */
    public static final Parcelable.Creator<DynamicInfo> CREATOR = new Creator<DynamicInfo>() {
        public DynamicInfo createFromParcel(Parcel source) {
            DynamicInfo discussInfo = new DynamicInfo();
            discussInfo.avatar = source.readString();
            discussInfo.nickName = source.readString();
            discussInfo.did = source.readString();
            discussInfo.urid = source.readString();
            discussInfo.content = source.readString();
            discussInfo.imageUrl = source.readString();
            discussInfo.pubtime = source.readString();
            discussInfo.state = source.readInt();
            discussInfo.type = source.readInt();
            discussInfo.support = source.readInt();
            discussInfo.neutral = source.readInt();
            discussInfo.opposition = source.readInt();
            discussInfo.comments = source.readInt();
            discussInfo.isSupport = source.readInt();
            discussInfo.isCollect = source.readInt();
            return discussInfo;
        }

        public DynamicInfo[] newArray(int size) {
            return new DynamicInfo[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(avatar);
        parcel.writeString(nickName);
        parcel.writeString(did);
        parcel.writeString(urid);
        parcel.writeString(content);
        parcel.writeString(imageUrl);
        parcel.writeString(pubtime);
        parcel.writeInt(state);
        parcel.writeInt(type);
        parcel.writeInt(support);
        parcel.writeInt(neutral);
        parcel.writeInt(opposition);
        parcel.writeInt(comments);
        parcel.writeInt(isSupport);
        parcel.writeInt(isCollect);
    }
}
